import 'dart:ui';

import 'package:densefog/const.dart';
import 'package:densefog/utils.dart';

class BlockItem {
  final int id;
  final double x;
  final double y;
  final double width;
  final double height;
  Rect rect;

  bool get isMainPosition => width == 2 && height == 2;

  BlockItem(this.id, this.x, this.y, this.width, this.height)
      : rect = Rect.fromLTWH(
          withPrecision4(x * cellSize),
          withPrecision4(y * cellSize),
          withPrecision4(width * cellSize),
          withPrecision4(height * cellSize),
        );

  factory BlockItem.copy(
    BlockItem source, {
    final int? id,
    final double? x,
    final double? y,
    final double? width,
    final double? height,
  }) {
    return BlockItem(
      id ?? source.id,
      x ?? source.x,
      y ?? source.y,
      width ?? source.width,
      height ?? source.height,
    );
  }
}
